package all.com.jinyongqunxiax.modules;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.randy.fundation.JxFunc;
import com.randy.fundation.Logger;

import all.com.jinyongqunxiax.R;
import all.com.jinyongqunxiax.component.JxForm;
import all.com.jinyongqunxiax.component.JxFormHeader;
import all.com.jinyongqunxiax.component.JxFormItemText;
import all.com.jinyongqunxiax.databinding.SkillAoyiDetailActivityBinding;
import all.com.jinyongqunxiax.model.mod.SkillAoyiManager;
import all.com.jinyongqunxiax.model.mod.manager.Mod;
import all.com.jinyongqunxiax.model.mod.manager.ModManager;
import all.com.jinyongqunxiax.view.JxHud;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import jy.game.components.wuxue.pojo.JyAoyi;

public class SkillAoyiDetailActivity extends AppCompatActivity {
    private Options                        options;
    private SkillAoyiDetailActivityBinding binding;
    JxForm form = new JxForm();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        options = new Options(getIntent());

        setTitle(options.item);

        Mod              mod     = ModManager.shared().get(options.mod);
        SkillAoyiManager manager = mod.skillAoyiManager;
        JyAoyi           model   = manager.map.get(options.item);

        binding = DataBindingUtil.setContentView(this, R.layout.skill_aoyi_detail_activity);

        RecyclerView recyclerView = binding.recyclerView;
        form.connect(this, recyclerView);

        if (model != null) {
            form.add(new JxFormHeader(0, "基本信息", null));

            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("名称").value("" + model.name).hint("name").value(), null));

            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("动画").value(model.animation).hint("animation").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("概率").value("" + model.probability).hint("probability").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("触发").value("" + model.start).hint("start").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("增益").value(model.buff).hint("buff").value(), null));

            form.add(new JxFormHeader(0, "条件", null));
            JxFunc.of(model.conditions).ifPresent(new JxFunc.Action<JyAoyi.Condition>() {
                @Override
                public void yield(@NonNull JyAoyi.Condition condition) {
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label(condition.type).value(condition.value + " " + condition.level).hint("animation").value(), null));

                }
            });
        }
        form.refresh();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.plus_button_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_add_button:
                JxHud.info("add menu clicked");
                break;
            default:
                Logger.w("not handle menu %d", item.getItemId());
                break;
        }
        return true;
    }

    public static class Options {
        String mod;
        String item;

        Options(Intent intent) {
            this.mod = intent.getStringExtra("mod");
            this.item = intent.getStringExtra("item");
        }

        static Intent intent(Context context, String mod, String item) {
            Intent intent = new Intent(context, SkillAoyiDetailActivity.class);
            intent.putExtra("mod", mod);
            intent.putExtra("item", item);
            return intent;
        }
    }
}
